﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DAO
{
    public class TaiKhoanDoanhNghiepDAO
    {
        private FDeal4Entities db;

        public TaiKhoanDoanhNghiepDAO()
        {
            db = new FDeal4Entities();
        }

        public List<TAIKHOANDOANHNGHIEP> LietKe()
        {
            return db.TAIKHOANDOANHNGHIEP.ToList();
        }

        public TAIKHOANDOANHNGHIEP LayID(string id)
        {
            var tl = db.TAIKHOANDOANHNGHIEP.SingleOrDefault(t => t.IDTAIKHOAN == id);
            return tl;
        }

        public TAIKHOANDOANHNGHIEP TimTen(String keyWord)
        {
            var tl = db.TAIKHOANDOANHNGHIEP.SingleOrDefault(t => t.TENDN.Contains(keyWord));
            return tl;
        }

        public bool Them(TAIKHOANDOANHNGHIEP tl)
        {
            try
            {
                db.TAIKHOANDOANHNGHIEP.AddObject(tl);
                db.SaveChanges();
                return true;
            }
            catch (System.Exception ex)
            {
                return false;
            }
        }

        public bool Xoa(TAIKHOANDOANHNGHIEP tl)
        {
            try
            {
                db.TAIKHOANDOANHNGHIEP.DeleteObject(tl);
                db.SaveChanges();
                return true;
            }
            catch (System.Exception ex)
            {
                return false;
            }
        }

        public bool Sua(TAIKHOANDOANHNGHIEP tl)
        {
            try
            {
                TAIKHOANDOANHNGHIEP t1 = db.TAIKHOANDOANHNGHIEP.Single(t => t.IDTAIKHOAN == tl.IDTAIKHOAN);
                t1.IDTAIKHOAN = tl.IDTAIKHOAN;
                t1.TENDN = tl.TENDN;
                t1.DIACHI = tl.DIACHI;
                t1.SDT = tl.SDT;
                t1.MOTA = tl.MOTA;

                db.SaveChanges();
                return true;
            }
            catch (System.Exception ex)
            {
            	return false;
            }
        }
    }
}
